package com.ch.swagger2.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author cj-ch
 * @date 2018/4/27 下午12:50
 */
@Data
@ApiModel(value = "通用顶层响应实体类")
public class Response<T> {

    @ApiModelProperty(value = "表示请求是否成功",example = "true",dataType = "Boolean",required = true)
    private Boolean success = false;

    @ApiModelProperty(value = "异常时返回的错误code",example = "10001",dataType = "String")
    private String errCode = "";

    @ApiModelProperty(value = "异常时返回的错误简要描述",example = "系统繁忙",dataType = "String")
    private String errMsg = "";

    @ApiModelProperty(value = "返回内容")
    private T data;

    public Response() {
    }

    public Response(Boolean success, String errCode, String errMsg, T data) {
        this.success = success;
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.data = data;
    }

    public static <D> Response success(D d){
        return new Response<D>(true,"","",d);
    }

    public static  Response success(){
        return new Response(true,"","",null);
    }

    public static Response error(String errCode,String errMsg){
        return new Response(false,errCode,errMsg,null);
    }


}
